package com.wenwei.sharebox.activity;

import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.TextView;

import com.wenwei.sharebox.R;
import com.wenwei.sharebox.adapter.CateGoryLeftAdapter;
import com.wenwei.sharebox.adapter.CateGoryRightAdapter;
import com.wenwei.sharebox.base.BaseActivity;
import com.wenwei.sharebox.bean.GoodCateBean;
import com.wenwei.sharebox.net.ApiManager;
import com.wenwei.sharebox.net.BaseSubscriber;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by Administrator on 2017/7/7. 666
 */
public class CateGoryActivity extends BaseActivity {
    @Bind(R.id.base_title)
    TextView baseTitle;
    @Bind(R.id.left_recycler)
    RecyclerView leftRecycler;
    @Bind(R.id.right_recycler)
    RecyclerView rightRecycler;

    private CateGoryLeftAdapter mLeftAdapter;
    private CateGoryRightAdapter mRightAdapter;
    @Override
    public int setLayoutResourceId() {
        return R.layout.activity_cate_gory;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }

    @Override
    protected void initView() {
        super.initView();
        baseTitle.setText("分类");

        leftRecycler.setLayoutManager(new LinearLayoutManager(mContext));
        mLeftAdapter = new CateGoryLeftAdapter(new CateGoryLeftAdapter.LeftCallBack() {
            @Override
            public void onLeftItemClick(List<GoodCateBean.ShopTweClassesBean> list) {
                mRightAdapter.setDataList(list);
                mRightAdapter.notifyDataSetChanged();
            }
        });
        leftRecycler.setAdapter(mLeftAdapter);

        rightRecycler.setLayoutManager(new GridLayoutManager(mContext,3));
        mRightAdapter = new CateGoryRightAdapter(new CateGoryRightAdapter.CallBack() {
            @Override
            public void onItemClick(int id,String name) {
                Bundle b1 = new Bundle();
                b1.putInt("type",3);
                b1.putInt("classId",id);
                b1.putString("className",name);
                goActivity(mContext, ShareCommonActivity.class,b1);
            }
        });
        rightRecycler.setAdapter(mRightAdapter);
    }

    @Override
    protected void initData() {
        super.initData();
        getCateGory();
    }

    @OnClick(R.id.base_back)
    public void onViewClicked() {
        finish();
    }

    private BaseSubscriber<ArrayList<GoodCateBean>> cateSubscriber;
    private void getCateGory(){
        cateSubscriber = new BaseSubscriber<ArrayList<GoodCateBean>>(mContext) {
            @Override
            public void onSuccess(ArrayList<GoodCateBean> goodCateBeen) {
                mLeftAdapter.setDataList(goodCateBeen);
                mLeftAdapter.notifyDataSetChanged();

                if(goodCateBeen.size()>0){
                    mRightAdapter.setDataList(goodCateBeen.get(0).getShopTweClasses());
                    mRightAdapter.notifyDataSetChanged();
                }

            }
        };
        ApiManager.getInstance().getGoodsCate(cateSubscriber);
    }
}
